#ifndef TEST_AIGAME_HPP
#define TEST_AIGAME_HPP

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Vector2.hpp>

#include <SmegCore/Game/GameBase.hpp>

#include <SmegAI/Movement/Pathfinding/Grid.hpp>
#include <SmegAI/Movement/Pathfinding/Algorithms/PathfindingAlgorithms.h>

namespace sf {
    class Font;
    class Text;

    class RectangleShape;
    class Sprite;
    class Texture;
}

class Test_PathfindingGame : public smeg::core::GameBase
{
public:
    ////////////////////////////////////////////////////////////
    /// Constructor/Destructor
    ////////////////////////////////////////////////////////////
                        Test_PathfindingGame();
    virtual             ~Test_PathfindingGame();

    ////////////////////////////////////////////////////////////
    /// Init the game
    ///
    /// \param _Mode :      Video mode to use (defines the width, height and depth of the rendering area of the window)
    /// \param _pTitle :    Title of the window
    /// \param _Style :     Window style
    /// \param _Settings :  Additional settings for the underlying OpenGL context
    ///
    ////////////////////////////////////////////////////////////
    virtual void        Init( sf::VideoMode _Mode, const char* _pTitle, sf::Uint32 _Style = sf::Style::Default, const sf::ContextSettings& _Settings = sf::ContextSettings() );

    ////////////////////////////////////////////////////////////
    /// DeInit the game
    ///
    ////////////////////////////////////////////////////////////
    virtual void        DeInit();

protected:
    enum ePathfindingType {
        eType_None  = 0,
        eType_AStar = 1 << 0,
        eType_JPS   = 1 << 1,
        eType_All   = eType_AStar | eType_JPS
    };

    ////////////////////////////////////////////////////////////
    /// Manage an incoming event
    ////////////////////////////////////////////////////////////
    virtual void        ManageEvent( const sf::Event& _Event );

    ////////////////////////////////////////////////////////////
    /// Call all the Update in the other systems
    ////////////////////////////////////////////////////////////
    virtual void        Update();

    ////////////////////////////////////////////////////////////
    /// Call all the Render in the other systems
    ////////////////////////////////////////////////////////////
    virtual void        Render();

    ////////////////////////////////////////////////////////////
    /// Show/Hide the help
    ////////////////////////////////////////////////////////////
    void                DisplayHelp();

    ////////////////////////////////////////////////////////////
    /// Find a path with the given algorithm
    ////////////////////////////////////////////////////////////
    void                FindPath( smeg::ai::BasePathfindingAlgorithm* _pAlgorithm, sf::Time& _AlgorithmTime );

    ////////////////////////////////////////////////////////////
    /// Clear all the pathfinding algorithms
    ////////////////////////////////////////////////////////////
    void                ClearAllPathfinding();

    /******************* Protected members ********************/
    const std::string   m_HelpString;
    std::string         m_FinalHelpString;
    sf::Font*           m_pFont;
    sf::Text*           m_pHelp;
    sf::Text*           m_pPathfindingInfo;
    bool                m_bShowHelp;
    
    bool                m_bDragBegin;
    bool                m_bDragEnd;
    bool                m_bDrawObstacles;
    bool                m_bClearWall;

    // Misc
    sf::Vector2f        m_BeginPoint;
    sf::Vector2f        m_EndPoint;
    
    sf::RectangleShape* m_pBeginShape;
    sf::RectangleShape* m_pEndShape;

    // Pathfinding
    smeg::ai::Grid*     m_pAIGrid;
    bool                m_bStepByStep;
    bool                m_bDoStep;
    ePathfindingType    m_PathfindingType;
    smeg::ai::BasePathfindingAlgorithm* m_pCurrentAlgorithm;
    sf::Clock           m_PathfindingClock;

    smeg::ai::AStar*    m_pAStar;
    sf::Time            m_AStarTime;
    smeg::ai::JumpPointSearch* m_pJumpPoint;
    sf::Time            m_JPSTime;
};


#endif // TEST_AIGAME_HPP
